import { HashCalculator } from "@smithy/hash-stream-node/src/main/ets/src/HashCalculator";
import { buffer } from "@kit.ArkTS";

export function createMockHash(): {
  updates: Uint8Array[];
  update: (data: Uint8Array) => void;
  digest: () => Promise<Uint8Array>;
  reset: () => void;
} {
  const mockHash: any = {
    updates: [] as Uint8Array[],
  };
  mockHash.update = (data: Uint8Array) => {
    mockHash.updates.push(data);
  };
  mockHash.digest = async () => {
    return Uint8Array.from([102, 111, 111]); // foo
  };
  mockHash.reset = () => {};
  return mockHash;
}



export const writePromise = (
  calculator: HashCalculator,
  chunk: buffer.Buffer,
  encoding: string = "utf-8"
): Promise<void> => {
  return new Promise((resolve, reject) => {
    calculator.write(new Uint8Array(chunk.buffer), encoding, (err:Error) => {
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });
};

export const listOfBuffers: buffer.Buffer[] = [buffer.from("foo"), buffer.from("bar"), buffer.from("buzz")];


